package exer;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author tongchen
 * @create 2023-04-02 16:04
 */
@WebServlet("/status")
public class GetStatus extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //首先设置两个数据格式
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        //根据不同的type设置编码格式
        String type = req.getParameter("type");
        System.out.println(type);
        if(type.equals("1")){
            resp.setStatus(200);
        }
        if(type.equals("2")){
            resp.setStatus(302);
        }
        if(type.equals("3")){
            resp.setStatus(303);

        }
        if(type.equals("4")){
            resp.setStatus(404);
            //跳转到tomcat页面
            resp.sendError(404);
        }
//写回最终数据
        resp.getWriter().write(resp.getStatus()+" ");

    }
}
